home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
CHASSIS_
/
MAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-27
|
9KB
|
268 lines
/************************************************************************************/
/* */
/* Program Name: Chassis */
/* Version: 4.2.1 */
/* */
/* by: Charles A. Hoffman */
/* */
/* ASSIST Consulting - or - GTE Laboratories */
/* P.O. Box 857 Mail Stop 24 */
/* Norwood, MA 02062 40 Sylvan Road */
/* Waltham, MA 02254 */
/* Phone: (617) 551-0185 */
/* Phone: (617) 466-2131 */
/* */
/************************************************************************************/
/* */
/* This program contains material from a version of the sample program */
/* "Chassis," and the application program "MacEden," which were originally */
/* created and copyrighted by Charles A. Hoffman. */
/* */
/************************************************************************************/
/* */
/* Compiled with Symantec Corp. THINK C 5.0.1 */
/* */
/************************************************************************************/
#include "MyHeaders.h"
/************************************************************************************/
/* MAIN */
/************************************************************************************/
main()
{
MainRetCode = 0; /* initialize return code */
myResRefNum = CurResFile(); /* Get own resource file number */
versRecHandle = (struct versRec **) GetResource ('vers',1); /* get vers resrce */
HLock (versRecHandle);
j = (int) (**versRecHandle).versChar[6];
k = (int) (**versRecHandle).versChar[6+1+j]; /* k is length of long string */
for (m = 0; m < k+2; m++)
versLongStr[m] = (**versRecHandle).versChar[6+j+1+m];
HUnlock (versRecHandle);
ReleaseResource (versRecHandle);
WorkRetCode = InitMac(); /* Start the managers */
WorkRetCode = ColorCheck(); /* Set "useColor" global */
UseResFile (initResRefNum);
prRecHdl = (THPrint) (NewHandle (sizeof (TPrint))); /* get handle for print rec */
PrintDefault (prRecHdl); /* initialize print rec */
prPortPtr = (TPPrPort) (NewPtr (sizeof (TPrPort))); /* get ptr to prnt port */
WorkRetCode = SetUpMenus(); /* set up the menus */
/** WorkRetCode = ShowInfoDlog(128); /* display the "About" dialog */
myDragRect = screenBits.bounds; /* Set the boundries... */
InsetRect(&myDragRect,10,10); /* ...for dragging */
for (j=0; j<windMax; j++) /* Indicate all entries in */
windTbl[j].windPtr = 0; /* windTbl are not in use */
SetPt (&nextTextPosit, 10,40); /* Set posit of first text wind */
workRegionH = NewRgn(); /* get region for TE clikloop */
WorkRetCode = MainGetProc(); /* put the main window up */
myQuitFlag = 0; /* set flag for main event loop */
WorkRetCode = FinderFilesProc(); /* process any files from finder */
/************************** */
/* Main Event Loop * */
/************************** */
while (myQuitFlag == 0) /* loop till quit */
{
GetMouse (&locMouse); /* where is the mouse? */
gMouse = locMouse; /* convert to .. */
LocalToGlobal(&gMouse); /* .. global coordinates */
mouseWindPart = FindWindow (gMouse, &mouseWindPtr); /* get ptr & part */
CursorSelect (mouseWindPtr, mouseWindPart, NIL); /* set cursor to match */
SystemTask(); /* let system have some time */
if (GetNextEvent(everyEvent, &myEvent) != nullEvent) /* if not nullEvent */
{
switch (myEvent.what)
{
case (activateEvt): /* activate or deactivate */
WorkRetCode =
WhichWindow((WindowPtr) myEvent.message, &windSub);
if (WorkRetCode == 0)
switch (windTbl[windSub].windRec.refCon)
{
case (ProcMain):
WorkRetCode = MainWindowProc();
break;
case (ProcText):
WorkRetCode = TextWindowProc();
break;
case (ProcHelp):
WorkRetCode = HelpWindowProc();
break;
}
break;
case (mouseDown):
WorkRetCode = MouseDownProc();
break;
case (mouseUp):
break;
case (diskEvt):
if (HiWord(myEvent.message) != noErr) /* if MountVol had err */
{ /* then initialize disk */
SysBeep(NIL); /* beep */
SetPt (&workPoint,30,40); /* position */
DIBadMount (workPoint, myEvent.message); /* initialize */
}
break;
case (networkEvt):
break;
case (driverEvt):
break;
case (app1Evt):
break;
case (app2Evt):
break;
case (app3Evt):
break;
case (app4Evt):
break;
case (keyUp):
break;
case (keyDown):
case (autoKey):
WorkRetCode = KeyDownProc();
break;
case (updateEvt):
WorkRetCode =
WhichWindow((WindowPtr) myEvent.message, &windSub);
if (WorkRetCode == 0)
{
BeginUpdate(windTbl[windSub].windPtr);
switch (windTbl[windSub].windRec.refCon)
{
case (ProcMain):
WorkRetCode = MainDrawProc();
break;
case (ProcText):
WorkRetCode = TextDrawProc();
break;
case (ProcHelp):
WorkRetCode = HelpDrawProc();
break;
}
EndUpdate(windTbl[windSub].windPtr);
}
break;
}
}
else
{
/************************************/
/* null event */
/* The system doesn't need our */
/* attention, so give one loop to */
/* the proc associated with the */
/* front window. */
/************************************/
workWindowPtr = FrontWindow(); /* which is front (active) ? */
WorkRetCode =
WhichWindow(workWindowPtr, &k); /* match ptr to table */
if (WorkRetCode == 0) /* if it's a good match */
{ /* then */
windSub = k; /* set the subscrpt */
switch (windTbl[windSub].windRec.refCon) /* window type */
{
case (ProcMain):
WorkRetCode = MainWindowProc();
break;
case (ProcText):
WorkRetCode = TextWindowProc();
break;
case (ProcHelp):
WorkRetCode = HelpWindowProc();
break;
}
}
}
}
/************************** */
/* End of Main Event Loop * */
/************************** */
WorkRetCode = MainCloseProc(); /* close main window */
WorkRetCode = ShutMac(); /* Shutdown routines */
return MainRetCode; /* ALL DONE !!! */
}
/************************************************************************************/
/* InitMac */
/* This function initializes the managers which will be used by this program. */
/************************************************************************************/
int InitMac(void)
{
int InitRetCode = 0; /* set the return code to good */
MaxApplZone(); /* expand heap to max size */
for (j=0; j<20; j++) /* get a bunch o' master pointers */
MoreMasters();
/************************************ */
/* NOTE - don't change the order * */
/* of these initialization routines* */
/************************************ */
InitGraf(&thePort); /* intiialize QuickDraw */
InitFonts(); /* initialize Font Manager */
InitWindows(); /* initialize Window Manager */
FlushEvents(everyEvent,0); /* initialize Event Manager */
InitMenus(); /* initialize Menu Manager */
TEInit(); /* initialize TextEdit */
InitDialogs(NIL); /* initialize Dialog Manager */
PrOpen(); /* initialize Print Manager */
InitCursor(); /* initialize Cursor to arrow */
DILoad(); /* load the Disk Init package */
/* Get resource file number after */
initResRefNum = CurResFile(); /* these loads and initializations */
return InitRetCode;
}
/************************************************************************************/
/* ShutMac */
/* This function does routines prior to program shutdown. */
/************************************************************************************/
int ShutMac(void)
{
int SMRetCode = 0; /* set the return code to good */
PrClose(); /* close memory of Print Mgr */
DIUnload(); /* delete disk init package */
DisposeRgn(workRegionH); /* release region for TE redraw */
return SMRetCode;
}